package com.deco.service.sys;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.deco.domain.vo.product.PartsCategoryVo;
import com.deco.domain.vo.sys.CmsAdvTypeVo;
import com.deco.logic.sys.CmsAdvTypeLogic;
import com.deco.service.CommonService;
import com.free.common.vo.PageResponseVo;
import com.free.common.vo.PageSearchVo;
import com.free.common.vo.ResultModel;

@Service
public class CmsAdvTypeService extends CommonService {
	   /*========================================================================*
     *                         Public Fields (公共属性)
     *========================================================================*/

    /*========================================================================*
     *                         Private Fields (私有属性)
     *========================================================================*/
    
    @Autowired
    private CmsAdvTypeLogic cmsAdvTypeLogic;
    /*========================================================================*
     *                         Construct Methods (构造方法)
     *========================================================================*/

    /*========================================================================*
     *                         Public Methods (公有方法)
     *========================================================================*/

    
    public CmsAdvTypeVo getCmsAdvType(int id){
    	return cmsAdvTypeLogic.getCmsAdvType(id);
    }
    
    public ResultModel save(CmsAdvTypeVo cmsAdvTypeVo){
        Timestamp nowTime = new Timestamp(System.currentTimeMillis());
    	if(cmsAdvTypeVo.getId() == null || cmsAdvTypeVo.getId() == 0){
			cmsAdvTypeVo.setCreateTime(nowTime);
    		cmsAdvTypeVo.setUpdateTime(nowTime);
    		cmsAdvTypeLogic.create(cmsAdvTypeVo);
    	}
    	else{
    		cmsAdvTypeVo.setUpdateTime(nowTime);
    		cmsAdvTypeLogic.update(cmsAdvTypeVo);
    	}
    	return ResultModel.success();
    }

	public ResultModel delete(int id) {
		cmsAdvTypeLogic.delete(id);
	  	return ResultModel.success();
	}
	
	public PageResponseVo<CmsAdvTypeVo> pageInfo(
			PageSearchVo<CmsAdvTypeVo> condition) {
		return cmsAdvTypeLogic.getPageInfo(condition);
	}

	public ResultModel batchDelete(Integer[] ids) {
		if(ids == null || ids.length == 0){
    		return ResultModel.success();
		}
    	int res = cmsAdvTypeLogic.batchDelete(ids);
    	if(res > 0){
    		return ResultModel.success();
		}
		return ResultModel.failure();
	}

	public List<CmsAdvTypeVo> getAll() {
		return cmsAdvTypeLogic.getAll();
	}

	public CmsAdvTypeVo selectByCode(String code){
    	return cmsAdvTypeLogic.selectByCode(code);
	}

    /*========================================================================*
     *                         Private Methods (私有方法)
     *========================================================================*/

}
